package MapDemo;

import java.util.HashMap;
import java.util.Scanner;

public class MapkeyTest {
    public static void main(String[] args) {
        //键盘录入
        Scanner sc = new Scanner(System.in);
        //提示:
        System.out.println("请您输入一句话");
        String line = sc.nextLine();
        //转char数组
        char[] chs = line.toCharArray();
        //弄一个容器HashMap<Character, Integer>
        HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
        //遍历数组
        for (char ch : chs) {
            //判断
            if (!hm.containsKey(ch)) {
                //直接添加到集合中
                hm.put(ch, 1);
            } else {
                hm.put(ch, hm.get(ch) + 1);
            }
        }
        //直接输出集合中的键值对关系
        System.out.println(hm);


    }
}
